let a: any = 1
console.log(a);

a = 'NaN'
console.log(a)

let b: any[] = [1, "123"]
// let b: number[] =[1,'undefined']
console.log(b);

let str = '1'
var str2: number = <any>str
console.log(str2);

let c = '123'
console.log(c);
// c = 321
console.log(c);

let global_num = 11111
class TTQ {
  age = 27
  static uname = 'ttq'
  getAge() {
    return this.age
  }
}
{
  let a1 = 3333
  console.log(a1);
}
// console.log(a1);

console.log(global_num);
console.log(TTQ.uname);
const t = new TTQ()
console.log(t.getAge());

console.log(global_num + '123');



for (const key of [10, 20, 30]) {
  console.log(key);

}

function log(): string {
  return '123'
}
function log1(name: string) {
  return name + 123
}
function log2(name: string, age?: number) {
  return name + 123
}

function fn(name: string = 'ttq') {
  console.log(name);

}
// fn()
console.log(log2('111'));

// 1 在元素后接[]
let arr1: number[] = [1, 2, 3]
// 2 使用数组泛型
let arr2: Array<number> = [1, 2, 3]
console.log(arr1);
console.log(arr2);
let arr: [number, string] = [1, '2']
arr.push('123123')
console.log(arr);

enum Status { success = 100, error = -99 }
let s: Status = Status.success
let f: Status = Status.error
console.log(s, f) // 100, -99

function fn1(): void {
  console.log(123);
}

function sum(...args: number[]): number {
  let num = 0
  for (const key of args) {
    num += key
  }
  return num
}

function sum2(a: number, b: number, ...args: number[]): number {
  let num = a + b
  for (const key of args) {
    num += key
  }
  return num
}
console.log('剩余参数2', sum2(1, 2, 3, 4, 5, 6));


function overloadingFn(x: number, y: number): number;
function overloadingFn(x: string, y: string): string;
// 最后是函数实现
function overloadingFn(x: any, y: any): any {
  if (typeof x === 'string') {
    return x + y
  } else {
    return x - y
  }
}
console.log(overloadingFn(1, 2)); // -1
console.log(overloadingFn('a', 'b')); // ab


interface FullName {
  firstName: string,
  secondName: string,
  age?: number
}
function getName(name: FullName) {
  return name
}

let testname = {
  firstName: 'h',
  secondName: 'l'
}
console.log(getName(testname));

interface Code {
  readonly type: string
}

var js: Code = { type: 'js' }

// js.type = 'tt'

